package jnpf.controller;
import cn.afterturn.easypoi.excel.ExcelExportUtil;
import cn.afterturn.easypoi.excel.entity.ExportParams;
import cn.afterturn.easypoi.excel.entity.params.ExcelExportEntity;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import jnpf.base.service.BillRuleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import jnpf.base.ActionResult;
import jnpf.base.vo.PageListVO;
import jnpf.base.vo.PaginationVO;
import jnpf.base.UserInfo;
import jnpf.base.vo.DownloadVO;
import jnpf.config.ConfigValueUtil;
import jnpf.exception.DataException;
import org.springframework.transaction.annotation.Transactional;
import jnpf.base.entity.ProvinceEntity;
import jnpf.model.whut_params.*;
import jnpf.model.whut_params.Whut_paramsPagination;
import jnpf.model.whut_params.Whut_paramsCrForm;
import jnpf.model.whut_params.Whut_paramsInfoVO;
import jnpf.model.whut_params.Whut_paramsListVO;
import jnpf.model.whut_params.Whut_paramsUpForm;
import jnpf.entity.*;
import jnpf.base.service.ProvinceService;
import jnpf.util.*;
import jnpf.base.util.*;
import jnpf.base.vo.ListVO;
import jnpf.util.context.SpringContext;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.ss.usermodel.Workbook;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import jnpf.entity.Whut_paramsEntity;
import jnpf.service.Whut_paramsService;
import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.multipart.MultipartFile;
import javax.validation.Valid;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.*;


/**
 *
 * whut_params
 * @版本： V3.2.0
 * @版权： 引迈信息技术有限公司（https://www.jnpfsoft.com）
 * @作者： JNPF开发平台组
 * @日期： 2024-10-05
 */
@Slf4j
@RestController
@Api(tags = "whut_params" , value = "example")
@RequestMapping("/api/example/Whut_params")
public class Whut_paramsController {


    @Autowired
    private GeneraterSwapUtil generaterSwapUtil;
    @Autowired
    private UserProvider userProvider;

    @Autowired
    private Whut_paramsService whut_paramsService;



    /**
     * 列表
     *
     * @param whut_paramsPagination
     * @return
     */
	@PostMapping("/getList")
    public ActionResult list(@RequestBody Whut_paramsPagination whut_paramsPagination)throws IOException{
        List<Whut_paramsEntity> list= whut_paramsService.getList(whut_paramsPagination);
        //处理id字段转名称，若无需转或者为空可删除
    for(Whut_paramsEntity entity:list){
    }
	List<Whut_paramsListVO> listVO=JsonUtil.getJsonToList(list,Whut_paramsListVO.class);
    for(Whut_paramsListVO whut_paramsVO:listVO){
            }



        PageListVO vo=new PageListVO();
        vo.setList(listVO);
        PaginationVO page=JsonUtil.getJsonToBean(whut_paramsPagination,PaginationVO.class);
        vo.setPagination(page);
        return ActionResult.success(vo);
    }


    /**
     * 创建
     *
     * @param whut_paramsCrForm
     * @return
     */
    @PostMapping
    @Transactional
    public ActionResult create(@RequestBody @Valid Whut_paramsCrForm whut_paramsCrForm) throws DataException {
        String mainId =RandomUtil.uuId();
        UserInfo userInfo=userProvider.get();
        Whut_paramsEntity entity = JsonUtil.getJsonToBean(whut_paramsCrForm, Whut_paramsEntity.class);
				entity.setId(mainId);
                whut_paramsService.save(entity);


        return ActionResult.success("创建成功");
}




    /**
    * 信息
    *
    * @param id
    * @return
    */
    @GetMapping("/{id}")
    public ActionResult<Whut_paramsInfoVO> info(@PathVariable("id") String id){
        Whut_paramsEntity entity= whut_paramsService.getInfo(id);
        Whut_paramsInfoVO vo=JsonUtil.getJsonToBean(entity, Whut_paramsInfoVO.class);

        return ActionResult.success(vo);
    }





   /**
    * 更新
    *
    * @param id
    * @return
    */
    @PutMapping("/{id}")
    @Transactional
    public ActionResult update(@PathVariable("id") String id,@RequestBody @Valid Whut_paramsUpForm whut_paramsUpForm) throws DataException {
        UserInfo userInfo=userProvider.get();
        Whut_paramsEntity entity= whut_paramsService.getInfo(id);
        if(entity!=null){
            Whut_paramsEntity subentity=JsonUtil.getJsonToBean(whut_paramsUpForm, Whut_paramsEntity.class);
            whut_paramsService.update(id, subentity);
        return ActionResult.success("更新成功");
        }else{
            return ActionResult.fail("更新失败，数据不存在");
        }
    }

   /**
    * 删除
    *
    * @param id
    * @return
    */
    @DeleteMapping("/{id}")
    @Transactional
    public ActionResult delete(@PathVariable("id") String id){
        Whut_paramsEntity entity= whut_paramsService.getInfo(id);
        if(entity!=null){
            whut_paramsService.delete(entity);

        }
        return ActionResult.success("删除成功");
    }


}
